using UnityEngine;
using System.Collections;

public class Fall : CharacterAction
{  
	public override void OnActionEnter(Character character)
	{ 
		float vy = character.pushForce.y > 5? character.pushForce.y: 5;
		float gravity = Physics.gravity.y;
		float duration = Mathf.Abs(vy/gravity*2);    // this duration change cause animationSpeed to 0. to be fixed
 
		character.rigidbodyRef.constraints = RigidbodyConstraints.FreezeRotationX | 
				RigidbodyConstraints.FreezeRotationZ;

		state.animationSpeed = duration / state.animationClip.length;
		state.nextState = null;
	}

	
	/** override to implement, and unregister event hanlders here*/
	public override void OnActionExit(Character character)
	{
        /*
        character.rigidbodyRef.constraints = RigidbodyConstraints.FreezeRotationX | 
            RigidbodyConstraints.FreezeRotationZ;
            */

        character.rigidbodyRef.constraints = RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotationX | 
			RigidbodyConstraints.FreezeRotationZ;
	}

	 
}

